//
//  ShopCartTableViewCell.m
//  News
//
//  Created by weige on 16/6/13.
//  Copyright © 2016年 weige. All rights reserved.
//

#import "ShopCartTableViewCell.h"
#import "BuyView.h"
#import "Goods.h"
#import "UIImageView+WebCache.h"
@interface ShopCartTableViewCell()
{
    UIImageView *goodImage;
    UILabel *goodName;
    UIImageView *giveImage;
    UILabel *labPrice;
    BuyView *buybtn;
    
}
@end
@implementation ShopCartTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createGoodCell];
    }
    return self;
    
}


-(void)createGoodCell
{
    goodImage=[[UIImageView alloc]init];
    [self addSubview:goodImage];
    goodName=[[UILabel alloc]init];
    goodName.textColor=TITLECOLOR;
    goodName.font=[UIFont systemFontOfSize:TitleFontSize];
    //文字自适应大小
    [goodName sizeToFit];
    [self addSubview:goodName];
    labPrice=[[UILabel alloc]init];
    labPrice.textColor=[UIColor redColor];
    labPrice.font=[UIFont systemFontOfSize:SubtitleFontsize];
    [labPrice sizeToFit];
    [self addSubview:labPrice];
    buybtn=[[BuyView alloc]init];
    [self addSubview:buybtn];
}

-(void)setGood:(Goods *)good
{
    [goodImage  sd_setImageWithURL:[NSURL URLWithString:good.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_square"]];
    goodName.text=good.name;
    labPrice.text=[NSString stringWithFormat:@"RMB:%@",good.partner_price];
    buybtn.goods=good;
    buybtn.isUserflag=YES;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    goodImage.frame=CGRectMake(10, 10, 60, 60);
    goodName.frame=CGRectMake(80, 10, ReceiptSize(goodName.text, TitleFontSize).width,  ReceiptSize(goodName.text, TitleFontSize).height);
    labPrice.frame=CGRectMake(80, self.frame.size.height-20-ReceiptSize(labPrice.text, SubtitleFontsize).height, ReceiptSize(labPrice.text, SubtitleFontsize).width, ReceiptSize(labPrice.text, SubtitleFontsize).height);
    buybtn.frame=CGRectMake(200, 30, 80,25);
   
}
@end
